//
//  RecordViewController.m
//  JiJinFinance
//
//  Created by 李东晓 on 15/12/10.
//  Copyright © 2015年 LiDongXiao. All rights reserved.
//

#import "RecordViewController.h"
#import "RecordViewCollectionViewCell.h"
@interface RecordViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UIScrollViewDelegate>
@property (nonatomic ,strong)UIScrollView * Scr;
@property (nonatomic ,strong)UICollectionView * CollectionView;
@property (nonatomic ,strong)UIView * carrier;

@property (strong, nonatomic) IBOutlet UIButton *ButAll;
@property (strong, nonatomic) IBOutlet UIButton *ButRefund;
@property (strong, nonatomic) IBOutlet UIButton *ButClear;

@end

@implementation RecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.title = @"投资记录";
    [_ButAll setBackgroundColor:RGBAColor(246, 246, 246, 1)];
    
    [self Scr];
    [self carrier];
    [self CollectionView];
    [self ViewXian];
    [self ButtColor];
}
//判断scrView的位置与button的颜色相对应
-(void)ButtColor
{

    
}


-(void)ViewXian
{
    UIView * Xian1 = [[UIView alloc]initWithFrame:CGRectMake(126*D_width, 82, 2, 17)];
    [Xian1 setBackgroundColor:RGBAColor(215, 215, 215, 1)];
    [self.view addSubview:Xian1];
    
    UIView * Xian2 = [[UIView alloc]initWithFrame:CGRectMake(245*D_height, 82, 2, 17)];
    [Xian2 setBackgroundColor:RGBAColor(215, 215, 215, 1)];
    [self.view addSubview:Xian2];
}


-(UIView * )carrier
{
    if (!_carrier) {
        _carrier = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kUIScreenWidth, kUIScreenHeight)];
        [_carrier setBackgroundColor:[UIColor yellowColor]];
        [_Scr addSubview:_carrier];
    }
    return _carrier;
}
-(UIScrollView * )Scr
{
    if (!_Scr) {
        _Scr = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 110, kUIScreenWidth, kUIScreenHeight-109)];
        [_Scr setContentSize:CGSizeMake(kUIScreenWidth * 3, 0)];
        [_Scr setBackgroundColor:RGBAColor(246, 246, 246, 1)];
        [_Scr setDelegate:self];
        [_Scr setPagingEnabled:YES];
        [self.view addSubview:_Scr];
    }
    return _Scr;
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //NSLog(@"%f",scrollView.contentOffset.x);
    if (_Scr.contentOffset.x >= 0 & _Scr.contentOffset.x < kUIScreenWidth/2) {
        [_ButAll setBackgroundColor:RGBAColor(246, 246, 246, 1)];
        
        [_ButRefund setBackgroundColor:[UIColor whiteColor]];
        [_ButClear setBackgroundColor:[UIColor whiteColor]];
    }else if (_Scr.contentOffset.x >= kUIScreenWidth/2 & _Scr.contentOffset.x <kUIScreenWidth*3/2){
        [_ButRefund setBackgroundColor:RGBAColor(246, 246, 246, 1)];
        
        [_ButAll setBackgroundColor:[UIColor whiteColor]];
        [_ButClear setBackgroundColor:[UIColor whiteColor]];
    }else if (_Scr.contentOffset.x >= kUIScreenWidth*3/2){
        [_ButClear setBackgroundColor:RGBAColor(246, 246, 246, 1)];
        
        [_ButAll setBackgroundColor:[UIColor whiteColor]];
        [_ButRefund setBackgroundColor:[UIColor whiteColor]];
    }
    
}
-(UICollectionView * )CollectionView
{
    if (!_CollectionView) {
        UICollectionViewFlowLayout * flowLayout = [[UICollectionViewFlowLayout alloc]init];
        flowLayout.itemSize = CGSizeMake(339, 113);
        
        flowLayout.minimumInteritemSpacing = 10;
        
        flowLayout.minimumLineSpacing = 10;
        
        flowLayout.sectionInset = UIEdgeInsetsMake(21, 18, 10, 19);
        
        _CollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kUIScreenWidth, kUIScreenHeight-110) collectionViewLayout:flowLayout];
        [_CollectionView setDataSource:self];
        [_CollectionView setDelegate:self];
        [_CollectionView setBackgroundColor:RGBAColor(246, 246, 246, 1)];
 
        [_carrier addSubview:_CollectionView];
        [_CollectionView registerClass:[RecordViewCollectionViewCell class] forCellWithReuseIdentifier:@"cellId"];
        
    }
    return _CollectionView;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 5;
}
-(UICollectionViewCell * )collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    RecordViewCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndexPath:indexPath];
    [cell setBackgroundColor:[UIColor whiteColor]];
    
    return cell;
}
- (IBAction)ButAllClick {
    NSLog(@"全部");
    
    [_Scr setContentOffset:CGPointMake(0, 0) animated:YES];
//    [_ButAll setBackgroundColor:RGBAColor(246, 246, 246, 1)];
//    
//    [_ButRefund setBackgroundColor:[UIColor whiteColor]];
//    [_ButClear setBackgroundColor:[UIColor whiteColor]];

}

- (IBAction)ButRefundClick {
    NSLog(@"还款中");
    
    [_Scr setContentOffset:CGPointMake(kUIScreenWidth, 0) animated:YES];
//    [_ButRefund setBackgroundColor:RGBAColor(246, 246, 246, 1)];
//    
//    [_ButAll setBackgroundColor:[UIColor whiteColor]];
//    [_ButClear setBackgroundColor:[UIColor whiteColor]];
}

- (IBAction)ButClearClick {
    NSLog(@"已算清");
    [_Scr setContentOffset:CGPointMake(kUIScreenWidth*2, 0) animated:YES];
//    [_ButClear setBackgroundColor:RGBAColor(246, 246, 246, 1)];
//    
//    [_ButAll setBackgroundColor:[UIColor whiteColor]];
//    [_ButRefund setBackgroundColor:[UIColor whiteColor]];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
